home *** CD-ROM | disk | FTP | other *** search
/ Personal Computer World 2009 February / PCWFEB09.iso / Software / Linux / SLAX 6.0.8 / slax-6.0.8.iso / slax / base / 006-devel.lzm / usr / include / kio / passdlg.h < prev    next >
Encoding:
C/C++ Source or Header  |  2006-01-19  |  5.7 KB  |  176 lines

  1. /* This file is part of the KDE libraries
  2.    Copyright (C) 2000 David Faure <faure@kde.org>
  3.    Copyright (C) 2000 Dawit Alemayehu <adawit@kde.org>
  4.  
  5.    This library is free software; you can redistribute it and/or
  6.    modify it under the terms of the GNU Library General Public
  7.    License version 2 as published by the Free Software Foundation.
  8.  
  9.    This library is distributed in the hope that it will be useful,
  10.    but WITHOUT ANY WARRANTY; without even the implied warranty of
  11.    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  12.    Library General Public License for more details.
  13.  
  14.    You should have received a copy of the GNU Library General Public
  15.    License along with this library; see the file COPYING.LIB.  If
  16.    not, write to the Free Software Foundation, Inc., 51 Franklin Street,
  17.    Fifth Floor, Boston, MA 02110-1301, USA.
  18. */
  19.  
  20. #ifndef __kio_pass_dlg_h__
  21. #define __kio_pass_dlg_h__
  22.  
  23. #include <kdialogbase.h>
  24.  
  25. class QGridLayout;
  26.  
  27. namespace KIO {
  28.  
  29. /**
  30.  * A dialog for requesting a login and a password from the end user.
  31.  *
  32.  * KIO-Slave authors are encouraged to use SlaveBase::openPassDlg
  33.  * instead of directly instantiating this dialog.
  34.  * @short dialog for requesting login and password from the end user
  35.  */
  36. class KIO_EXPORT PasswordDialog : public KDialogBase
  37. {
  38.     Q_OBJECT
  39.  
  40. public:
  41.     /**
  42.      * Create a password dialog.
  43.      *
  44.      * @param prompt        instructional text to be shown.
  45.      * @param user          username, if known initially.
  46.      * @param enableKeep    if true, shows checkbox that makes password persistent until KDE is shutdown.
  47.      * @param modal         if true, the dialog will be modal (default:true).
  48.      * @param parent        the parent widget (default:NULL).
  49.      * @param name          the dialog name (default:NULL).
  50.      */
  51.     PasswordDialog( const QString& prompt, const QString& user,
  52.                     bool enableKeep = false, bool modal=true,
  53.                     QWidget* parent=0, const char* name=0 );
  54.  
  55.     /**
  56.      * Destructor
  57.      */
  58.     ~PasswordDialog();
  59.  
  60.     /**
  61.      * Sets the prompt to show to the user.
  62.      * @param prompt        instructional text to be shown.
  63.      */
  64.     void setPrompt( const QString& prompt );
  65.  
  66.     /**
  67.      * Adds a comment line to the dialog.
  68.      *
  69.      * This function allows you to add one additional comment
  70.      * line to this widget.  Calling this function after a
  71.      * comment has already been added will not have any effect.
  72.      *
  73.      * @param label       label for comment (ex:"Command:")
  74.      * @param comment     the actual comment text.
  75.      */
  76.     void addCommentLine( const QString& label, const QString comment );
  77.  
  78.     /**
  79.      * Returns the password entered by the user.
  80.      * @return the password
  81.      */
  82.     QString password() const;
  83.  
  84.     /**
  85.      * Returns the username entered by the user.
  86.      * @return the user name
  87.      */
  88.     QString username() const;
  89.  
  90.     /**
  91.      * Determines whether supplied authorization should
  92.      * persist even after the application has been closed.
  93.      * @return true to keep the password
  94.      */
  95.     bool keepPassword() const;
  96.  
  97.     /**
  98.      * Check or uncheck the "keep password" checkbox.
  99.      * This can be used to check it before showing the dialog, to tell
  100.      * the user that the password is stored already (e.g. in the wallet).
  101.      * enableKeep must have been set to true in the constructor.
  102.      */
  103.     void setKeepPassword( bool b );
  104.  
  105.     /**
  106.      * Sets the username field read-only and sets the
  107.      * focus to the password field.
  108.      *
  109.      * @param readOnly true to set the user field to read-only
  110.      */
  111.     void setUserReadOnly( bool readOnly );
  112.  
  113.     /**
  114.      * @deprecated. Use setUserReadOnly(bool).
  115.      */
  116.     KDE_DEPRECATED void setEnableUserField( bool enable, bool=false ) {
  117.     setUserReadOnly( !enable );
  118.     };
  119.  
  120.     /**
  121.      * Presets the password.
  122.      * @param password the password to set
  123.      * @since 3.1
  124.      */
  125.     void setPassword( const QString& password );
  126.  
  127.     /**
  128.      * Presets a number of login+password pairs that the user can choose from.
  129.      * The passwords can be empty if you simply want to offer usernames to choose from.
  130.      * This is incompatible with setUserReadOnly(true).
  131.      * @param knownLogins map of known logins: the keys are usernames, the values are passwords.
  132.      * @since 3.4
  133.      */
  134.     void setKnownLogins( const QMap<QString, QString>& knownLogins );
  135.  
  136.     /**
  137.      * A convienence static method for obtaining authorization
  138.      * information from the end user.
  139.      *
  140.      *
  141.      * @param user          username
  142.      * @param pass          password
  143.      * @param keep          pointer to flag that indicates whether to keep password (can be null)
  144.      * @param prompt        text to display to user.
  145.      * @param readOnly      make the username field read-only.
  146.      * @param caption       set the title bar to given text.
  147.      * @param comment       extra comment to display to user.
  148.      * @param label         optinal label for extra comment.
  149.      *
  150.      * @return Accepted/Rejected based on the user choice.
  151.      */
  152.     static int getNameAndPassword( QString& user, QString& pass, bool* keep,
  153.                                    const QString& prompt = QString::null,
  154.                                    bool readOnly = false,
  155.                                    const QString& caption = QString::null,
  156.                                    const QString& comment = QString::null,
  157.                                    const QString& label = QString::null );
  158.  
  159. private slots:
  160.     void slotKeep( bool );
  161.     void slotActivated( const QString& userName );
  162.  
  163. private:
  164.     void init( const QString&, const QString&, bool );
  165.  
  166. protected:
  167.     virtual void virtual_hook( int id, void* data );
  168. private:
  169.     struct PasswordDialogPrivate;
  170.     PasswordDialogPrivate* d;
  171. };
  172.  
  173. }
  174.  
  175. #endif
  176.